home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / games2 / rotise12.zip / REPORT.C < prev    next >
Text File  |  1993-03-28  |  36KB  |  1,249 lines

  1. /* report.c
  2.     Jonathan Arnold 1991
  3.  
  4.     Routines to generate the final report.
  5.         report - main routine
  6. */
  7.  
  8. #include <string.h>
  9.  
  10. #include "rotise.h"
  11.  
  12. #include "rdb.h"
  13.  
  14. /* External data referenced */
  15. extern RDB_TEAM *RotoTeams;                /* roster.c - First team in list */
  16. extern char LeagueName[];
  17. extern int Weeks;                                /* stenog.c */
  18.  
  19. /* Local data publicly available */
  20. BOOL Use_IBM_Chars = FALSE;                    /* whether to use extended IBM char set */
  21.  
  22. /* Private function prototypes */
  23. void crunch_rotise PROTO( (void) );
  24. void batter_out PROTO( (FILE *outfp, RDB_TEAM *team, int wsF ) );
  25. void pitcher_out PROTO( (FILE *outfp, RDB_TEAM *team, int wsF ) );
  26. void print_batstat PROTO( (FILE *outfp, int slotN, char    *name, char *team, char    *sal, 
  27.     char *con, char *wk1, PDBT_BATTER *batP, PDBT_BATTER *wkbP) );
  28. void print_pchstat PROTO( (FILE *outfp, int slotN, char *name, char *team, char *salstr, 
  29.     char *con, char *wk1, PDBT_PITCHER *pchP, PDBT_PITCHER *wkpP) );
  30. void do_standings PROTO( (FILE *outfp) );
  31. void print_standings PROTO( (FILE    *outfp) );
  32. void print_wstandings PROTO( (FILE    *outfp) );
  33. void crunch_batter PROTO( (RDB_TEAM*team) );
  34. void crunch_pitcher PROTO( (RDB_TEAM*team) );
  35. void print_bathdr PROTO( (FILE *) );
  36. static RDB_PLAYER *next_player PROTO( ( RDB_TEAM *teamP, RDB_PLAYER *playerP ) );
  37. static freeprint PROTO( (PDB_PNAME *) );
  38.  
  39. /* Private data */
  40. static FILE *FlfP;
  41. static UWORD Flposmask;
  42. static char *Flpos;
  43. static char *Flposdesc;
  44. static int FlposC;
  45.  
  46.  
  47.  
  48. /* Generate freelist */
  49. void freelist ARGLIST( (flfname) )
  50.      FARG( char *flfname )
  51. {
  52.  
  53.     if ( ( FlfP = fopen( flfname, "w" ) ) == NULL )
  54.     {    /* Can't open freelist file */
  55.         fprintf( stderr, "freelist: can't open file \"%s\"\n", flfname );
  56.         return;
  57.     }
  58.  
  59.     for ( Flposmask = 0x0001; ;Flposmask <<= 1 )
  60.     {    /* Do all different positions */
  61.         Flpos = mask_to_pos( Flposmask );
  62.         if ( Flpos == NULL )
  63.         {    /* Mask of 0 will be the "catch-all" position */
  64.             Flposmask = 0;
  65.             Flposdesc = "Unknown";
  66.         }
  67.         else
  68.             Flposdesc = mask_to_posdesc( Flposmask );
  69.  
  70.         FlposC = 0;
  71.         pdb_walk( freeprint );
  72.  
  73.         if ( Flpos == NULL )
  74.         {    /* All done with positional lists */
  75.             break;
  76.         }
  77.     }
  78.  
  79.     fclose( FlfP );
  80. }
  81.  
  82. /* Freelist output routine */
  83. static int
  84. freeprint ARGLIST( ( pnameP ) )
  85.      FARG( PDB_PNAME *pnameP )
  86. {
  87.     UWORD    pos;                                /* Player's position mask */
  88.     PDB_PNAME fullname;                    /* Player's full name */
  89.     PDATA *pdataP;                            /* Player data */
  90.     PDBT_BATTER    batblk;                        /* Batter data */
  91.     PDBT_PITCHER    pchblk;                    /* Pitcher data */
  92.     char    rptname[50];                    /* Buffer for name */
  93.  
  94.     if ( pnameP == NULL )
  95.     {
  96.         if ( FlposC == 0 )
  97.             fprintf( FlfP, "%s: None eligible.\n", Flposdesc );
  98.         fprintf( FlfP, "\n\n\n\n" );
  99.         return ( TRUE );
  100.     }
  101.  
  102.     
  103.  
  104.     if ( !pdb_getpos( pnameP, &pos ) )
  105.     {    /* Can't get position for player -- this shouldn't happen. */
  106.         fprintf( stderr, "freeprint: can't get positions for %s %s!\n",
  107.             &pnameP->pn_fname[0], &pnameP->pn_lname[0] );
  108.         return ( TRUE );
  109.     }
  110.  
  111.     pdataP = pdb_pdata( &pnameP->pn_lname[0], &pnameP->pn_fname[0],
  112.                                 pnameP->batter );
  113.     if ( pdataP == NULL )
  114.     {    /* This shouldn't happen either. */
  115.         fprintf( stderr, "freeprint: can't get player status.\n" );
  116.         return ( FALSE );
  117.     }
  118.  
  119.     if ( pdataP->zorch != PLAYER_FREE )
  120.         return ( TRUE );
  121.  
  122.    if ( ( Flposmask == 0 ) && ( pos != 0 ) )
  123.     {    /* Mask of 0 is for "other" free players (w/o positions) */
  124.         return ( TRUE );
  125.     }
  126.     else if ( ( Flposmask != 0 ) && ( ( pos & Flposmask ) == 0 ) )
  127.     {    /* Not valid at this position */
  128.         return ( TRUE );
  129.     }
  130.  
  131.     if ( FlposC++ == 0 )
  132.     {    /* First guy this position? */
  133.         fprintf( FlfP, "%s\n", Flposdesc );
  134.         fprintf( FlfP, "-----------------------------------\n" );
  135.     }
  136.  
  137.     pdb_name( pnameP, Weeks, &fullname );
  138.     sprintf( &rptname[0], "%s, %s", 
  139.             &fullname.pn_lname[0], &fullname.pn_fname[0] );
  140.     fprintf( FlfP, "%-15s %3s ", &rptname[0], &fullname.pn_team[0] );
  141.  
  142.  
  143.     /* Now print current year's stats for this guy */
  144.     if ( Flposmask == POS_P )
  145.     { /* Do pitcher stats */
  146.         if ( !pdb_pitchstats( pnameP, 0, Weeks, &pchblk ) )
  147.             fprintf( FlfP, "<stats unavailable>" );
  148.         else
  149.         {
  150.             fprintf( FlfP, "%2dW %2dS %5.2fERA %5.2fRatio %3d.%dIP %3dER %3dH %3dBB",
  151.                 pchblk.ps_won, pchblk.ps_saved,
  152.                 era( &pchblk ), ratio( &pchblk ),
  153.                 pchblk.ps_outs/3, pchblk.ps_outs%3,
  154.                 pchblk.ps_er, pchblk.ps_hits, pchblk.ps_bb
  155.             );
  156.         }
  157.     }
  158.     else if ( Flposmask != 0 )
  159.     { /* Do batter stats */
  160.         if ( !pdb_batstats( pnameP, 0, Weeks, &batblk ) )
  161.             fprintf( FlfP, "<stats unavailable>" );
  162.         else
  163.         {
  164.             fprintf( FlfP, "%.3fAvg (%3d/%-3d) %2dHR %3dBI %3dSB",
  165.                 avg( &batblk ), batblk.bs_hits, batblk.bs_atbat,
  166.                 batblk.bs_hr, batblk.bs_rbi, batblk.bs_sb );
  167.         }
  168.     }
  169.  
  170.     if ( strlen( pdataP->status ) > 0 )
  171.     { /* some kind of status */
  172.         if ( strcmp( pdataP->status, WAIVED_STRING ) == 0 && pdataP->week != Weeks )
  173.         { /* too long ago, clear status */
  174.                 pdataP->status[0] = '\0';
  175.         }
  176.         else
  177.         {
  178.             if ( Flposmask == POS_P )
  179.                 fprintf( FlfP, "\n  " );
  180.             fprintf( FlfP, "   **** %s on %s ****", pdataP->status, pdataP->date );
  181.         }
  182.     }
  183.  
  184.     fprintf( FlfP, "\n" );
  185.  
  186.  
  187.     return ( TRUE );
  188. }
  189.         
  190.  
  191. /* Generate worksheet file */
  192. void worksheet ARGLIST( (fnameP) )
  193.      FARG( char *fnameP )
  194. {
  195.     FILE        *wfP;
  196.     RDB_TEAM *teams;
  197.  
  198.     if ( ( wfP = fopen( fnameP, "w" ) ) == NULL )
  199.     {
  200.         fprintf( stderr, "worksheet: can not open file \"%s\"\n", fnameP );
  201.         return;
  202.     }
  203.  
  204.     crunch_rotise();
  205.  
  206.     for ( teams = RotoTeams; teams != NULL; teams = teams->next )
  207.     { /* print each team worksheet */
  208.         fprintf( wfP, "%*s%s\n", 50- (strlen(LeagueName)/2), " ", LeagueName );
  209.         batter_out( wfP, teams, TRUE );
  210.         fprintf( wfP, "\n");
  211.         pitcher_out( wfP, teams, TRUE );
  212.  
  213.         /* send a form feed */
  214.         printf( "%c", 0x0C );
  215.     }
  216.  
  217.     fclose( wfP );
  218.  
  219. }
  220.  
  221.  
  222.  
  223. void report NOARGLIST
  224. {
  225.     RDB_TEAM *teams;
  226.  
  227.     crunch_rotise();
  228.  
  229.     for ( teams = RotoTeams; teams != NULL; teams = teams->next )
  230.     { /* print each team stats */
  231.         fprintf( stdout, "%*s%s\n", 50-(strlen(LeagueName)/2), " ", LeagueName );
  232.         batter_out( stdout, teams, FALSE );
  233.         fprintf( stdout, "\n");
  234.         pitcher_out( stdout, teams, FALSE );
  235.  
  236.         /* send a form feed */
  237.         printf( "%c", 0x0C );
  238.     }
  239.  
  240.     do_standings( stdout );
  241.  
  242.     /* Print histograms */
  243.     printf( "\n\n          Ordered rankings year to date -- year/week\n\n" );
  244.     standings();
  245.     print_histogram( stdout, FALSE );
  246.  
  247.     printf( "\n\n\n\n          Ordered rankings week %d -- week/year\n\n", Weeks );
  248.     wk_standings();
  249.     print_histogram( stdout, TRUE );
  250. }
  251.  
  252.  
  253.  
  254. /* Simple routine to draw dividing line, which is done quite often */
  255. void draw_divider ARGLIST( (outfp) )
  256.     FARG(        FILE *outfp     )
  257. {
  258.     if ( !Use_IBM_Chars ) 
  259.         fprintf( outfp, "\n-----------------------------------------------------------+--------------------");
  260.     else
  261.         fprintf( outfp, "\n───────────────────────────────────────────────────────────┼────────────────────");
  262. }
  263.  
  264. /*
  265.     void batter_out( FILE *outfp, RDB_TEAM *team, int wsF )
  266.      Print out the complete and weekly stats for all batters on the active roster as of
  267.         the final week in data.
  268.  
  269.  ACCEPTS:
  270.     FILE *outfp - FILE to output report to
  271.     RDB_TEAM *team - Rotisserie team to report about
  272.     wsF - TRUE if making a worksheet, FALSE otherwise.
  273.  
  274.  RETURNS:
  275.     Nothing
  276. */
  277. void batter_out ARGLIST( (outfp, team, wsF) )
  278.     NFARG(     FILE *outfp )
  279.     NFARG(     RDB_TEAM *team )
  280.      FARG(    int wsF )
  281. {            
  282.     PDBT_BATTER batblk, weekblk;
  283.     RDB_PLAYER *player;
  284.     PDB_PNAME pname;
  285.     BOOL done_reserved;
  286.     PDATA *pdata;
  287.     char salstr[10], week1str[10];
  288.  
  289.     /* Init week */
  290.     team->bweek.bs_atbat = team->bweek.bs_hits = 
  291.         team->bweek.bs_1b =    team->bweek.bs_2b =
  292.         team->bweek.bs_3b = team->bweek.bs_hr =
  293.         team->bweek.bs_bb =    team->bweek.bs_hpb =
  294.         team->bweek.bs_rbi = team->bweek.bs_sb =
  295.         team->bweek.bs_cs = 0;
  296.  
  297.  
  298.     fprintf( outfp, "=== %s ===", team->name );
  299.     fprintf( outfp, "\tGM: %s\n", team->owner );
  300.     print_bathdr( outfp );
  301.  
  302.     for ( player = NULL; ; )
  303.     {
  304.         /* Find next player in slot-order */
  305.         player = next_player( team, player );
  306.         if ( player == NULL )
  307.             break;
  308.  
  309.         if ( slot_get( player->slot )->slot[0] == 'P' )
  310.         { /* check for active batters */
  311.             continue;
  312.         }
  313.  
  314.         if ( (player->status != STATUS_ACTIVE && player->end != Weeks) ||
  315.             (player->status == STATUS_ACTIVE && player->start > Weeks) )
  316.         { /* either old player or brand new player - not important */
  317.             continue;
  318.         }
  319.  
  320.         /* Read from start to current week for active players */
  321.         if ( !pdb_batstats( &player->pname, player->start-1,
  322.                 Weeks, &batblk ))
  323.         { /* can't find player in database! */    
  324.             batblk.bs_atbat = batblk.bs_hits = 
  325.                 batblk.bs_1b =    batblk.bs_2b =
  326.                 batblk.bs_3b = batblk.bs_hr =
  327.                 batblk.bs_bb =    batblk.bs_hpb =
  328.                 batblk.bs_rbi = batblk.bs_sb =
  329.                 batblk.bs_cs = 0;
  330.           }
  331.  
  332.         sprintf( salstr, "$%3.1f0", (float)player->salary/10.0 );
  333.       sprintf( week1str, "%2d", player->start-1 );
  334.         if ( !pdb_name( &player->pname, Weeks, &pname ) )
  335.         { /* couldn't find it, init */
  336.             strcpy( pname.pn_team, "---" );
  337.         }
  338. #ifdef OLD_REPORT
  339.         print_batstat( outfp, player->slot, player->name,
  340.                 pname.pn_team, salstr, contract_string( player->contract ), week1str, &batblk, NULL, NULL );
  341. #endif
  342.  
  343.         /* Now print stat for current week */
  344.         if ( !pdb_batstats( &player->pname, Weeks-1, Weeks, &weekblk ))
  345.         { /* can't find player in database! */    
  346.             weekblk.bs_atbat = weekblk.bs_hits = 
  347.                 weekblk.bs_1b =    weekblk.bs_2b =
  348.                 weekblk.bs_3b = weekblk.bs_hr =
  349.                 weekblk.bs_bb =    weekblk.bs_hpb =
  350.                 weekblk.bs_rbi = weekblk.bs_sb =
  351.                 weekblk.bs_cs = 0;
  352.           }
  353.  
  354. #ifdef OLD_REPORT
  355.         print_batstat( outfp, "", "           Week:",
  356.                     "", " ", " ", "  ", &weekblk, NULL, NULL );
  357. #else
  358.         pdata = pdb_pdata( player->pname.pn_lname, player->pname.pn_fname, TRUE );
  359.         if ( pdata == NULL || pdata->status[0] == '\0' ||
  360.             strcmp( pdata->status, WAIVED_STRING ) == 0 )
  361.         { /* no status or WAIVED by team, so print weekly stats */
  362.             print_batstat( outfp, player->slot, player->name,
  363.                 pname.pn_team, salstr, contract_string( player->contract ), week1str, &batblk,
  364.                 &weekblk );
  365.         }
  366.         else
  367.         { /* no weekly stuff, cuz we are going to show status instead */
  368.             print_batstat( outfp, player->slot, player->name,
  369.                 pname.pn_team, salstr, contract_string( player->contract ), week1str, &batblk,
  370.                 NULL );
  371.             fprintf( outfp, "****%s on %s****", pdata->status, pdata->date );
  372.         }
  373.  
  374. #endif
  375.  
  376.  
  377.         /* Total up week stats */
  378.         team->bweek.bs_atbat += weekblk.bs_atbat;
  379.         team->bweek.bs_hits += weekblk.bs_hits;
  380.         team->bweek.bs_1b += weekblk.bs_1b;
  381.         team->bweek.bs_2b += weekblk.bs_2b;
  382.         team->bweek.bs_3b += weekblk.bs_3b;
  383.         team->bweek.bs_hr += weekblk.bs_hr;
  384.         team->bweek.bs_bb += weekblk.bs_bb;
  385.         team->bweek.bs_hpb += weekblk.bs_hpb;
  386.         team->bweek.bs_rbi += weekblk.bs_rbi;
  387.         team->bweek.bs_sb += weekblk.bs_sb;
  388.         team->bweek.bs_cs += weekblk.bs_cs;
  389.  
  390.     }
  391.  
  392.     /* print out old other stats */
  393.  
  394.     /* First show reserved players */
  395.     draw_divider( outfp );
  396.  
  397.     done_reserved = FALSE;
  398.  
  399.     for ( player = team->players; player != NULL; player = player->next )
  400.     { /* print out each reserved player's data */
  401.         if ( slot_get( player->slot )->slot[0] == 'P' )
  402.         { /* checking for batters */
  403.             continue;
  404.         }
  405.  
  406.         if ( (player->status != STATUS_RESERVE) ||
  407.             (player->status == STATUS_RESERVE && player->end == Weeks) )
  408.         { /* either not on reserved, or just reserved this week */
  409.             continue;
  410.         }
  411.  
  412.         /* Read from start to current week for active players */
  413.         if ( !pdb_batstats( &player->pname, player->start-1,
  414.                 player->end, &batblk ))
  415.         { /* can't find player in database! */    
  416.             batblk.bs_atbat = batblk.bs_hits = 
  417.                 batblk.bs_1b =    batblk.bs_2b =
  418.                 batblk.bs_3b = batblk.bs_hr =
  419.                 batblk.bs_bb =    batblk.bs_hpb =
  420.                 batblk.bs_rbi = batblk.bs_sb =
  421.                 batblk.bs_cs = 0;
  422.           }
  423.  
  424.         sprintf( salstr, "$%3.1f0", (float)player->salary/10.0 );
  425.       sprintf( week1str, "%2d", player->start-1 );
  426.         if ( !pdb_name( &player->pname, Weeks, &pname ) )
  427.         { /* couldn't find it, init */
  428.             strcpy( pname.pn_team, "---" );
  429.         }
  430.  
  431.         if ( !done_reserved )
  432.         { /* draw reserved header */
  433.             fprintf( outfp, "\n%-59s%1s%-15s", "RESERVED", (Use_IBM_Chars?"│":"|"), " Status" );
  434.             draw_divider( outfp );
  435.             done_reserved = TRUE;
  436.         }
  437.  
  438.         print_batstat( outfp, player->slot, player->name,
  439.             pname.pn_team, salstr, contract_string( player->contract ), week1str, &batblk,
  440.             NULL );
  441.  
  442.         /* Now add status */
  443.         pdata = pdb_pdata( player->pname.pn_lname, player->pname.pn_fname, TRUE );
  444.         if ( pdata != NULL )
  445.             fprintf( outfp, "%5s %s %5s", pdata->status, (strlen(pdata->date)?"on":""), pdata->date );
  446.     }
  447.  
  448.     /* now for the rest */
  449.     print_batstat( outfp, 99, "All others", "", "", "", "", &team->oldb, NULL );
  450.     draw_divider( outfp );
  451.  
  452.     /* now, print team totals for batters */
  453.     print_batstat( outfp, 99, "TOTALS:", "", "", "","", &team->batters , &team->bweek);
  454.     if ( !Use_IBM_Chars )
  455.         fprintf( outfp, "\n-----------------------------------------------------------+--------------------");
  456.     else
  457.         fprintf( outfp, "\n───────────────────────────────────────────────────────────┴────────────────────");
  458. #ifdef OLD_REPORT
  459.     print_batstat( outfp, "", "Week Totals:", "", "", "", "", &team->bweek , NULL);
  460. #endif
  461. }
  462.  
  463. /*
  464.     void pitcher_out( FILE *outfp, RDB_TEAM *team, int wsF )
  465.      Print out the complete and weekly stats for all pitchers on the active roster as of
  466.         the final week in data.
  467.  
  468.  ACCEPTS:
  469.     FILE *outfp - FILE to output report to
  470.     RDB_TEAM *team - Rotisserie team to report about
  471.     wsF - TRUE if making a worksheet, FALSE otherwise
  472.  
  473.  RETURNS:
  474.     Nothing
  475. */
  476. void pitcher_out ARGLIST( (outfp, team, wsF) )
  477.     NFARG(    FILE *outfp )
  478.     NFARG(    RDB_TEAM *team )
  479.      FARG(     int wsF )
  480. {
  481.     PDBT_PITCHER pchblk, weekblk;
  482.     RDB_PLAYER *player;
  483.     PDB_PNAME pname;
  484.     PDATA *pdata;
  485.     char salstr[10], week1str[10];
  486.     BOOL done_reserved;
  487.  
  488.     /* Clear the week totals */
  489.     team->pweek.ps_outs = team->pweek.ps_er = team->pweek.ps_bb = team->pweek.ps_hits =
  490.         team->pweek.ps_won  = team->pweek.ps_lost = team->pweek.ps_saved = 0;
  491.  
  492. #ifdef OLD_REPORT
  493.     print_pchstat( outfp, "POS", "     Name", "Team", " Sal", "C", "WK1", (PDB_PITCHER *)NULL );
  494. #else
  495.     print_pchstat( outfp, 99, NULL, NULL, NULL, NULL, NULL, (PDB_PITCHER *)NULL, NULL );
  496. #endif
  497.  
  498.     for ( player = NULL; ; )
  499.     {
  500.         /* Find next player in slot-order */
  501.         player = next_player( team, player );
  502.         if ( player == NULL )
  503.             break;
  504.  
  505.         if ( slot_get( player->slot)->slot[0] != 'P' )
  506.         { /* Bypass non-pitchers */
  507.             continue;
  508.         }
  509.  
  510.         if ( (player->status != STATUS_ACTIVE && player->end != Weeks) ||
  511.             (player->status == STATUS_ACTIVE && player->start > Weeks) )
  512.         { /* either old player or brand new player - not important */
  513.             continue;
  514.         }
  515.  
  516.         /* Get and print total stats for player */
  517.         if ( !pdb_pitchstats( &player->pname, player->start-1,
  518.                         Weeks, &pchblk ))
  519.         { /* can't find it! */
  520.             pchblk.ps_outs = pchblk.ps_er = pchblk.ps_bb = pchblk.ps_hits =
  521.                 pchblk.ps_won  = pchblk.ps_lost = pchblk.ps_saved = 0;
  522.         }
  523.  
  524.         sprintf( salstr, "$%3.1f0", (float)player->salary / 10.0 );
  525.       sprintf( week1str, "%2d", player->start-1 );
  526.         if ( !pdb_name( &player->pname, Weeks, &pname ) )
  527.         { /* couldn't find it, init */
  528.             strcpy( pname.pn_team, "---" );
  529.         }
  530. #ifdef OLD_REPORT
  531.         print_pchstat( outfp, player->slot, player->name, 
  532.             pname.pn_team, salstr, contract_string( player->contract ),
  533.             week1str, &pchblk );
  534. #endif
  535.  
  536.         /* Now do week */
  537.         if ( !pdb_pitchstats( &player->pname, Weeks-1,
  538.                         Weeks, &weekblk ))
  539.         { /* can't find it! */
  540.             weekblk.ps_outs = weekblk.ps_er = weekblk.ps_bb = weekblk.ps_hits =
  541.                 weekblk.ps_won  = weekblk.ps_lost = weekblk.ps_saved = 0;
  542.         }
  543. #ifdef OLD_REPORT
  544.         print_pchstat( outfp, "", "             Week",
  545.                     "", "", "","",&pchblk );
  546. #else
  547.         pdata = pdb_pdata( player->pname.pn_lname, player->pname.pn_fname, FALSE );
  548.         if ( pdata == NULL || pdata->status[0] == '\0' ||
  549.             strcmp( pdata->status, WAIVED_STRING ) == 0 )
  550.         { /* no status, or WAIVED by team, so print week stats */    
  551.            print_pchstat( outfp, player->slot, player->name, 
  552.                pname.pn_team, salstr, contract_string( player->contract ),
  553.                week1str, &pchblk, &weekblk );
  554.         }
  555.         else
  556.         { /* no weekly stuff, cuz we are going to show status instead */
  557.            print_pchstat( outfp, player->slot, player->name, 
  558.                pname.pn_team, salstr, contract_string( player->contract ),
  559.                week1str, &pchblk, NULL );
  560.             fprintf( outfp, "****%s on %s****", pdata->status, pdata->date );
  561.         }
  562. #endif
  563.  
  564.         /* Add in week's totals */
  565.         team->pweek.ps_outs += weekblk.ps_outs;
  566.         team->pweek.ps_er += weekblk.ps_er;
  567.         team->pweek.ps_bb += weekblk.ps_bb;
  568.         team->pweek.ps_hits += weekblk.ps_hits;
  569.         team->pweek.ps_won  += weekblk.ps_won ;
  570.         team->pweek.ps_lost += weekblk.ps_lost;
  571.         team->pweek.ps_saved += weekblk.ps_saved;
  572.  
  573.     }
  574.  
  575.     /* now for rest of team */
  576.  
  577.     /* First show reserved players */
  578.     draw_divider( outfp );
  579.  
  580.     done_reserved = FALSE;
  581.     for ( player = team->players; player != NULL; player = player->next )
  582.     { /* print each player who is a pitcher */
  583.         if ( slot_get( player->slot)->slot[0] != 'P' )
  584.         { /* Bypass non-pitchers */
  585.             continue;
  586.         }
  587.  
  588.         if ( (player->status != STATUS_RESERVE) ||
  589.             (player->status == STATUS_RESERVE && player->end == Weeks) )
  590.         { /* either not on reserved, or just reserved this week */
  591.             continue;
  592.         }
  593.  
  594.         /* Get and print total stats for player */
  595.         if ( !pdb_pitchstats( &player->pname, player->start-1,
  596.                         player->end, &pchblk ))
  597.         { /* can't find it! */
  598.             pchblk.ps_outs = pchblk.ps_er = pchblk.ps_bb = pchblk.ps_hits =
  599.                 pchblk.ps_won  = pchblk.ps_lost = pchblk.ps_saved = 0;
  600.         }
  601.  
  602.         sprintf( salstr, "$%3.1f0", (float)player->salary / 10.0 );
  603.       sprintf( week1str, "%2d", player->start-1 );
  604.         if ( !pdb_name( &player->pname, Weeks, &pname ) )
  605.         { /* couldn't find it, init */
  606.             strcpy( pname.pn_team, "---" );
  607.         }
  608.  
  609.         if ( !done_reserved )
  610.         { /* draw reserved header */
  611.             fprintf( outfp, "\n%-59s%1s%-15s", "RESERVED", (Use_IBM_Chars?"│":"|"), " Status" );
  612.             draw_divider( outfp );
  613.             done_reserved = TRUE;
  614.         }
  615.  
  616.         print_pchstat( outfp, player->slot, player->name, 
  617.             pname.pn_team, salstr, contract_string( player->contract ),
  618.             week1str, &pchblk, NULL );
  619.  
  620.         /* Now add status */
  621.         pdata = pdb_pdata( player->pname.pn_lname, player->pname.pn_fname, FALSE );
  622.         if ( pdata != NULL )
  623.             fprintf( outfp, "%5s %s %5s", pdata->status, (strlen(pdata->date)?"on":""), pdata->date );
  624.     }
  625.  
  626.     /* now for the rest */
  627.     print_pchstat( outfp, 99, "All others", "", "", "", "", &team->oldp, NULL );
  628.     draw_divider( outfp );
  629.  
  630.     /* and now show totals */
  631.     print_pchstat( outfp, 99, "TOTALS:", "","","", "", &team->pitchers, &team->pweek );
  632.  
  633.     if ( !Use_IBM_Chars )
  634.         fprintf( outfp, "\n-----------------------------------------------------------+--------------------\n");
  635.     else
  636.         fprintf( outfp, "\n───────────────────────────────────────────────────────────┴────────────────────\n");
  637.  
  638. #ifdef OLD_REPORT
  639.     print_pchstat( outfp, "", "Week Totals:", "","","", "", &team->pweek );
  640.     fprintf( outfp, "\n" );
  641. #endif
  642. }
  643. #ifdef OLD_REPORT
  644. void print_batstat ARGLIST( (outfp, pos, name, team, sal, con, wk1, batP, wkbP) )
  645.     NFARG(    FILE        *outfp )
  646.     NFARG(    char        *pos )
  647.     NFARG(    char        *name )
  648.     NFARG(    char        *team )
  649.     NFARG(    char        *sal )
  650.    NFARG(    char     *con )
  651.    NFARG(    char     *wk1 )
  652.     NFARG(    PDBT_BATTER    *batP )
  653.     FARG(        PDBT_BATTER    *wkbP )
  654. {
  655.     if ( batP == NULL )
  656.     { /* NULL means print the header */
  657.         fprintf( outfp,"%3s %-20s%-4s  %-4s%1s %3s%4s  %4s %4s  %3s %3s %3s %3s %3s %3s\n",
  658.              pos, name, team, sal, con, wk1, 
  659.              "Avg", "AB", "H", "1B", "2B", "3B", "HR", "RBI", "SB"
  660.             );
  661.         return;
  662.     }
  663.  
  664.     /* Print the batter stats */
  665.     fprintf( outfp, "%3s %-20s%-4s %-5s%1s %2s %.3f %4d %4d %4d %3d %3d %3d %3d %3d\n",
  666.             pos, name, team, sal, con, wk1,
  667.             avg( batP ),
  668.             batP->bs_atbat, batP->bs_hits,
  669.             batP->bs_1b, batP->bs_2b, batP->bs_3b, batP->bs_hr,
  670.             batP->bs_rbi, batP->bs_sb
  671.      );
  672. }
  673.  
  674. void print_pchstat ARGLIST( (outfp, pos, name, team, salstr, pchP) )
  675.     NFARG(    FILE        *outfp )
  676.     NFARG(    char        *pos )
  677.     NFARG(    char        *name )
  678.     NFARG(    char        *team )
  679.     NFARG(    char        *salstr )
  680.     NFARG(    char         *con )
  681.     NFARG(    char        *wk1 )
  682.     FARG(        PDBT_PITCHER    *pchP )
  683. {
  684.     if ( pchP == NULL )
  685.     { /* NULL means print the header */
  686.         fprintf( outfp,"%3s %-18s%-4s %-5s%1s %3s %4s  %2s %2s %2s %3s %3s  %3s %4s  %6s\n",
  687.             pos, name, team, salstr, con, wk1,
  688.             "IP", "W", "L", "SV",
  689.             "ER", "H", "BB", "ERA", "Ratio"
  690.             );
  691.         return;
  692.     }
  693.  
  694.     /* Print the pitcher stats */
  695.     fprintf( outfp,  "%3s %-18s%-4s %-5s%1s %2s %4d.%d %2d %2d %2d %3d %4d %3d %5.2f %6.3f\n",
  696.             pos, name, team, salstr, con, wk1,
  697.             pchP->ps_outs/3, pchP->ps_outs%3,
  698.             pchP->ps_won,
  699.             pchP->ps_lost,
  700.             pchP->ps_saved,
  701.             pchP->ps_er,
  702.             pchP->ps_hits,
  703.             pchP->ps_bb,
  704.             era( pchP ),
  705.             ratio( pchP )
  706.         );
  707. }
  708. #else
  709. void print_bathdr ARGLIST( (outfp) )
  710.     FARG(        FILE *outfp    )
  711. {
  712.     if ( !Use_IBM_Chars )
  713.         fprintf( outfp, "-----------------------------------------------------------+--------------------\n");
  714.     else
  715.         fprintf( outfp, "───────────────────────────────────────────────────────────┬────────────────────\n");
  716.  
  717.     fprintf( outfp, "%-19s%-40s%1s%-18s\n", "BATTING", "  Year to date", (Use_IBM_Chars?"│":"|"),
  718.         "  This Week" );
  719.     fprintf( outfp, "%-19s%-3s %-3s %5s%1s %3s %4s %3s %3s %3s %4s%1s %2s %2s %2s %2s %2s %4s",
  720.         "   Name", "Pos", "Tm", "Sal ", "C", "AB", "H", "HR", "RBI", "SB", "Avg", (Use_IBM_Chars?"│":"|"),
  721.         "AB", "H", "HR", "BI", "SB", "Avg" );
  722.     draw_divider( outfp );
  723. }
  724.  
  725. void print_batstat ARGLIST( (outfp, slot, name, team, sal, con, wk1, batP, wkbP) )
  726.     NFARG(    FILE        *outfp )
  727.     NFARG(    int        slot )
  728.     NFARG(    char        *name )
  729.     NFARG(    char        *team )
  730.     NFARG(    char        *sal )
  731.    NFARG(    char     *con )
  732.    NFARG(    char     *wk1 )
  733.     NFARG(    PDBT_BATTER    *batP )
  734.     FARG(        PDBT_BATTER    *wkbP )
  735. {
  736.     RDB_SLOT *slotP;
  737.     char *pos;
  738.  
  739.     if ( slot == 99 )
  740.     {    /* This is for blank position. */
  741.         pos = "";
  742.     }
  743.     else
  744.     {
  745.         slotP = slot_get( slot );
  746.         if ( slotP == NULL )
  747.             pos = "";
  748.         else
  749.             pos = slotP->slot;
  750.     }
  751.  
  752.     fprintf(outfp,"\n");
  753.     fprintf( outfp, "%-19.19s%-3s %-3s %5s%1s%4d %4d %3d %3d %3d .%03d%1s",
  754.         name, pos, team, sal, con,
  755.         batP->bs_atbat, batP->bs_hits,
  756.         batP->bs_hr, batP->bs_rbi, batP->bs_sb,
  757.         (int) (avg( batP )*1000.0), (Use_IBM_Chars?"│":"|") );
  758.     if ( wkbP != NULL )
  759.     { /* print out weekly stats */
  760.         fprintf( outfp, "%3d%3d%3d%3d%3d .%03d",
  761.             wkbP->bs_atbat, wkbP->bs_hits, wkbP->bs_hr, wkbP->bs_rbi, wkbP->bs_sb,
  762.             (int) (avg( wkbP )*1000.0)
  763.             );
  764.     }
  765. }
  766.  
  767. void print_pchstat ARGLIST( (outfp, slot, name, team, salstr, 
  768.                     con, wk1, pchP, wkpP) )
  769.     NFARG(    FILE        *outfp )
  770.     NFARG(    int        slot )
  771.     NFARG(    char        *name )
  772.     NFARG(    char        *team )
  773.     NFARG(    char        *salstr )
  774.     NFARG(    char         *con )
  775.     NFARG(    char        *wk1 )
  776.     NFARG(    PDBT_PITCHER    *pchP )
  777.     FARG(        PDBT_PITCHER    *wkpP )
  778. {
  779.     float rat, er;
  780.  
  781. #ifdef USE_POS
  782.     RDB_SLOT *slotP;
  783.     char *pos;
  784.  
  785.     if ( slot == 99 )
  786.     {    /* This is for blank position. */
  787.         pos = "";
  788.     }
  789.     else
  790.     {
  791.         slotP = slot_get( slot );
  792.         if ( slotP == NULL )
  793.             pos = "";
  794.         else
  795.             pos = slotP->slot;
  796.     }
  797. #endif
  798.  
  799.     if ( pchP == NULL )
  800.     { /* NULL means print the header */
  801.         if ( !Use_IBM_Chars )
  802.             fprintf( outfp, "-----------------------------------------------------------+--------------------\n");
  803.         else
  804.             fprintf( outfp, "───────────────────────────────────────────────────────────┬────────────────────\n");
  805.         fprintf( outfp, "%-19s%-40s%1s%-18s\n", "PITCHING", "  Year to date", (Use_IBM_Chars?"│":"|"),
  806.             "  This Week" );
  807.         fprintf( outfp, "%-15s %3s %5s%1s%3s %3s %6s %4s %3s %4s%5s%1s%2s %2s%5s %4s%5s",
  808.             "  Name", "Tm", "Sal ", "C", "W", "S", "IP  ", "H ", "BB", "Rat.", "ERA",
  809.             (Use_IBM_Chars?"│":"|"), "W", "S", "IP", "Rat.", "ERA" );
  810.         draw_divider( outfp );
  811.     }
  812.     else
  813.     { /* Print the pitcher stats */
  814.         rat = ratio( pchP );
  815.         er = era( pchP );
  816.         fprintf( outfp, "\n%-15.15s %3s %5s%1s%3d %3d %4d.%1d %4d %3d ",
  817.             name, team, salstr, con,
  818.             pchP->ps_won,
  819.             pchP->ps_saved,
  820.             pchP->ps_outs/3, pchP->ps_outs%3,
  821.             pchP->ps_hits,
  822.             pchP->ps_bb
  823.             );
  824.  
  825.         if ( rat >= 100.0 )
  826.         { /* just overflow it */
  827.             fprintf( outfp, "****" );
  828.         }
  829.         else
  830.             fprintf( outfp, "%4.2f", rat );
  831.  
  832.         if ( er >= 100.0 )
  833.             fprintf( outfp, " ****" );
  834.         else
  835.             fprintf( outfp, "%5.2f", er );
  836.         
  837.         fprintf( outfp, "%1s", (Use_IBM_Chars?"│":"|") );
  838.         
  839.         if ( wkpP != NULL )
  840.         { /* print out weekly stats */
  841.             fprintf( outfp,  "%2d %2d%3d.%1d",
  842.                 wkpP->ps_won,
  843.                 wkpP->ps_saved,
  844.                 wkpP->ps_outs/3, wkpP->ps_outs%3
  845.                 );
  846.  
  847.             rat = ratio( wkpP );
  848.             er = era( wkpP );
  849.             if ( rat >= 100.0 )
  850.             { /* just overflow it */
  851.                 fprintf( outfp, "****" );
  852.             }
  853.             else
  854.                 fprintf( outfp, "%5.2f", rat );
  855.  
  856.             if ( er >= 100.0 )
  857.                 fprintf( outfp, " ****" );
  858.             else
  859.                 fprintf( outfp, "%5.2f", er );
  860.         }
  861.     }
  862. }                                
  863. #endif  /* OLD_REPORT */
  864.  
  865. void do_standings ARGLIST( (outfp) )
  866.     FARG(        FILE     *outfp )
  867. {
  868.     /* Go ahead and generate the standings */
  869.     print_standings( outfp );
  870.  
  871.     /* Form Feed */
  872.     fprintf( outfp, "%c", 0x0C );
  873.  
  874.     /* And now the weekly ones */
  875.     print_wstandings( outfp );
  876.  
  877.     /* Form Feed */
  878.     fprintf( outfp, "%c", 0x0C );
  879. }
  880.  
  881. /* Do the total standings */
  882. void print_standings ARGLIST( (outfp) )
  883.     FARG(        FILE        *outfp )
  884. {
  885.     int        kk, tt;
  886.     int        tcnt;
  887.     RDB_TEAM    *team;
  888.     RDB_TEAM    *teams[MAX_TEAMS];    /* Sorted */
  889.  
  890.     for( tcnt = 0, team = RotoTeams; team != NULL; team = team->next, tcnt++ )
  891.     { /* Get sorted team list */
  892.         for( kk = 0; kk < tcnt; ++kk )
  893.         { /* Find where this team goes */
  894.             if ( team->totalPnts > teams[kk]->totalPnts )
  895.             {
  896.                 break;
  897.             }
  898.         }
  899.  
  900.         for ( tt = tcnt; tt > kk; tt-- )
  901.         { /* shuffle lower placed teams down one */
  902.             teams[tt] = teams[tt-1];
  903.         }
  904.  
  905.         teams[kk] = team;
  906.     }
  907.  
  908.     fprintf( outfp, "\n\n                   ==== %s ====\n", LeagueName );
  909.     fprintf( outfp, "                     ------>> Week: %d <<------\n\n", Weeks );
  910.     for( kk = 0; kk < tcnt; ++kk )
  911.     { /* Print the standings */
  912.         fprintf( outfp, "%15s%-25.25s   %4.1f\n", " ",
  913.             teams[kk]->name, teams[kk]->totalPnts );
  914.     }
  915.  
  916.     fprintf( outfp, "\n\n" );
  917.  
  918.     /* Print batter points */
  919.     fprintf( outfp, "%25s   %4s  %4s  %4s  %4s  %4s  %4s  %4s  %4s\n",
  920.         "     TEAM     ",
  921.         "Avg.", "Pts.",
  922.         "HR", "Pts.",
  923.         "RBI", "Pts.",
  924.         "SB", "Pts."
  925.         );
  926.  
  927.     for( kk = 0; kk < tcnt; ++kk )
  928.     { /* Print batter points */
  929.         team = teams[kk];
  930.         fprintf( outfp,
  931.           "%25s  %4.3f  %4.1f  %4d  %4.1f  %4d  %4.1f  %4d  %4.1f\n",
  932.             team->name,
  933.             avg( &team->batters ), team->points[RANK_AVG],
  934.             team->batters.bs_hr, team->points[RANK_HR],
  935.             team->batters.bs_rbi, team->points[RANK_RBI],
  936.             team->batters.bs_sb, team->points[RANK_SB]
  937.         );
  938.     }
  939.  
  940.  
  941.     fprintf( outfp, "\n%25s  %4s  %4s %5s  %4s  %7s  %4s  %5s  %4s\n",
  942.         "     TEAM     ",
  943.         "Wins", "Pts.",
  944.         "Saves", "Pts.",
  945.         "ERA ", "Pts.",
  946.         "Ratio", "Pts."
  947.         );
  948.  
  949.     for( kk = 0; kk < tcnt; ++kk )
  950.     { /* Print pitcher points */
  951.         team = teams[kk];
  952.         fprintf( outfp,
  953.           "%25s  %4d  %4.1f %5d  %4.1f  %7.3f  %4.1f  %5.3f  %4.1f\n",
  954.             team->name,
  955.             team->pitchers.ps_won, team->points[RANK_WINS],
  956.             team->pitchers.ps_saved, team->points[RANK_SVS],
  957.             era( &team->pitchers ), team->points[RANK_ERA],
  958.             ratio( &team->pitchers ), team->points[RANK_RATIO]
  959.         );
  960.     }
  961. }
  962.  
  963. /* Do the weekly standings */
  964. void print_wstandings ARGLIST( (outfp) )
  965.     FARG(        FILE        *outfp )
  966. {
  967.     int        kk, tt;
  968.     int        tcnt;
  969.     RDB_TEAM    *team;
  970.     RDB_TEAM    *teams[MAX_TEAMS];    /* Sorted */
  971.  
  972.     wk_standings();
  973.  
  974.     for( tcnt = 0, team = RotoTeams; team != NULL; team = team->next, tcnt++ )
  975.     { /* Get sorted team list */
  976.         for( kk = 0; kk < tcnt; ++kk )
  977.         { /* Find where this team goes */
  978.             if ( team->totalPnts > teams[kk]->totalPnts )
  979.             {
  980.                 break;
  981.             }
  982.         }
  983.  
  984.         for ( tt = tcnt; tt > kk; tt-- )
  985.         { /* shuffle lower placed teams down one */
  986.             teams[tt] = teams[tt-1];
  987.         }
  988.  
  989.         teams[kk] = team;
  990.     }
  991.  
  992.     fprintf( outfp, "\n\nWeek %d Single Week Standings:\n\n", Weeks );
  993.     for( kk = 0; kk < tcnt; ++kk )
  994.     { /* Print the standings */
  995.         fprintf( outfp, "%15s%-25.25s   %4.1f\n", " ",
  996.             teams[kk]->name, teams[kk]->totalPnts );
  997.     }
  998.  
  999.     fprintf( outfp, "\n\n" );
  1000.  
  1001.     /* Print batter points */
  1002.     fprintf( outfp, "%25s   %4s  %4s  %4s  %4s  %4s  %4s  %4s  %4s\n",
  1003.         "     TEAM     ",
  1004.         "Avg.", "Pts.",
  1005.         "HR", "Pts.",
  1006.         "RBI", "Pts.",
  1007.         "SB", "Pts."
  1008.         );
  1009.  
  1010.     for( kk = 0; kk < tcnt; ++kk )
  1011.     { /* Print batter points */
  1012.         team = teams[kk];
  1013.         fprintf( outfp,
  1014.           "%25s  %4.3f  %4.1f  %4d  %4.1f  %4d  %4.1f  %4d  %4.1f\n",
  1015.             team->name,
  1016.             avg( &team->bweek ), team->points[RANK_AVG],
  1017.             team->bweek.bs_hr, team->points[RANK_HR],
  1018.             team->bweek.bs_rbi, team->points[RANK_RBI],
  1019.             team->bweek.bs_sb, team->points[RANK_SB]
  1020.         );
  1021.     }
  1022.  
  1023.     fprintf( outfp, "\n%25s  %4s  %4s %5s  %4s  %7s  %4s  %5s  %4s\n",
  1024.         "     TEAM     ",
  1025.         "Wins", "Pts.",
  1026.         "Saves", "Pts.",
  1027.         "ERA ", "Pts.",
  1028.         "Ratio", "Pts."
  1029.         );
  1030.  
  1031.     for( kk = 0; kk < tcnt; ++kk )
  1032.     { /* Print pitcher points */
  1033.         team = teams[kk];
  1034.         fprintf( outfp,
  1035.           "%25s  %4d  %4.1f %5d  %4.1f  %7.3f  %4.1f  %5.3f  %4.1f\n",
  1036.             team->name,
  1037.             team->pweek.ps_won, team->points[RANK_WINS],
  1038.             team->pweek.ps_saved, team->points[RANK_SVS],
  1039.             era( &team->pweek ), team->points[RANK_ERA],
  1040.             ratio( &team->pweek ), team->points[RANK_RATIO]
  1041.         );
  1042.     }
  1043. }
  1044.  
  1045. /* crunch_rotise()
  1046.  * run through all the teams, doing totals and weekly tallys.
  1047.  *    Also, make up the new standings.
  1048.  */
  1049. void crunch_rotise NOARGLIST
  1050. {
  1051.     RDB_TEAM *team;
  1052.  
  1053.     for ( team = RotoTeams; team != NULL; team = team->next )
  1054.     { /* crunch all the teams */
  1055.         crunch_batter( team );
  1056.         crunch_pitcher( team );
  1057.     }
  1058.  
  1059.     standings();
  1060. }
  1061.  
  1062. /* get totals and old stats for a team */
  1063. void crunch_batter ARGLIST( (team) )
  1064.     FARG(    RDB_TEAM *team )
  1065. {
  1066.     PDBT_BATTER batblk;
  1067.     RDB_PLAYER *player;
  1068.  
  1069.     /* start totals off at zero */
  1070.     team->batters.bs_atbat = team->batters.bs_hits = team->batters.bs_1b =
  1071.         team->batters.bs_2b = team->batters.bs_3b =
  1072.         team->batters.bs_hr = team->batters.bs_bb = team->batters.bs_hpb =
  1073.         team->batters.bs_rbi = team->batters.bs_sb = team->batters.bs_cs = 0;
  1074.  
  1075.     team->oldb.bs_atbat = team->oldb.bs_hits = team->oldb.bs_1b =
  1076.         team->oldb.bs_2b = team->oldb.bs_3b = team->oldb.bs_hr =
  1077.         team->oldb.bs_bb = team->oldb.bs_hpb = team->oldb.bs_rbi =
  1078.         team->oldb.bs_sb = team->oldb.bs_cs = 0;
  1079.  
  1080.     for ( player = team->players; player != NULL; player = player->next )
  1081.     { /* print out each player's data */
  1082.         if ( slot_get( player->slot )->slot[0] != 'P' )
  1083.         { /* get batters for totalling */
  1084.  
  1085.             if ( player->status == STATUS_MINORS )
  1086.             { /* don't even bother with this player */
  1087.                 continue;
  1088.             }
  1089.  
  1090.             /* Read from start to Weeks for active players, or end for inactive
  1091.                 ones.  Make sure we don't go too far tho */
  1092.             if ( !pdb_batstats( &player->pname, player->start-1, 
  1093.                     (player->status == STATUS_ACTIVE ? Weeks :
  1094.                         (player->end < Weeks? player->end : Weeks)),
  1095.                 &batblk ))
  1096.             { /* can't find player in database, so just zero it! */    
  1097.                 batblk.bs_atbat = batblk.bs_hits = batblk.bs_1b =
  1098.                     batblk.bs_2b = batblk.bs_3b = batblk.bs_hr =
  1099.                     batblk.bs_bb = batblk.bs_hpb = batblk.bs_rbi =
  1100.                     batblk.bs_sb = batblk.bs_cs = 0;
  1101.             }
  1102.  
  1103.             if ( player->start < Weeks &&
  1104.                    player->end < Weeks &&
  1105.                     player->status != STATUS_ACTIVE &&
  1106.                     player->status != STATUS_RESERVE )
  1107.             {    /* total up 'old', non-reserved, batters */
  1108.                 team->oldb.bs_atbat += batblk.bs_atbat;
  1109.                 team->oldb.bs_hits += batblk.bs_hits;
  1110.                 team->oldb.bs_1b += batblk.bs_1b;
  1111.                 team->oldb.bs_2b += batblk.bs_2b;
  1112.                 team->oldb.bs_3b += batblk.bs_3b;
  1113.                 team->oldb.bs_hr += batblk.bs_hr;
  1114.                 team->oldb.bs_bb += batblk.bs_bb;
  1115.                 team->oldb.bs_hpb += batblk.bs_hpb;
  1116.                 team->oldb.bs_rbi += batblk.bs_rbi;
  1117.                 team->oldb.bs_sb += batblk.bs_sb;
  1118.                 team->oldb.bs_cs += batblk.bs_cs;
  1119.             }
  1120.  
  1121.             if ( player->start <= Weeks )
  1122.             { /* add in totals */
  1123.                 team->batters.bs_atbat += batblk.bs_atbat;
  1124.                 team->batters.bs_hits += batblk.bs_hits;
  1125.                 team->batters.bs_1b += batblk.bs_1b;
  1126.                 team->batters.bs_2b += batblk.bs_2b;
  1127.                 team->batters.bs_3b += batblk.bs_3b;
  1128.                 team->batters.bs_hr += batblk.bs_hr;
  1129.                 team->batters.bs_bb += batblk.bs_bb;
  1130.                 team->batters.bs_hpb += batblk.bs_hpb;
  1131.                 team->batters.bs_rbi += batblk.bs_rbi;
  1132.                 team->batters.bs_sb += batblk.bs_sb;
  1133.                 team->batters.bs_cs += batblk.bs_cs;
  1134.             }
  1135.         }
  1136.     }
  1137. }
  1138.  
  1139. void crunch_pitcher ARGLIST( (team) )
  1140.     FARG(    RDB_TEAM *team )
  1141. {
  1142.     PDBT_PITCHER pchblk;
  1143.     RDB_PLAYER *player;
  1144.  
  1145.     team->pitchers.ps_outs = team->pitchers.ps_er = team->pitchers.ps_bb = team->pitchers.ps_hits =
  1146.         team->pitchers.ps_won  = team->pitchers.ps_lost = team->pitchers.ps_saved = 0;
  1147.     team->oldp.ps_outs = team->oldp.ps_er = team->oldp.ps_bb = team->oldp.ps_hits =
  1148.         team->oldp.ps_won  = team->oldp.ps_lost = team->oldp.ps_saved = 0;
  1149.  
  1150.     for ( player = team->players; player != NULL; player = player->next )
  1151.     { /* print each player who is a pitcher */
  1152.         if ( slot_get( player->slot )->slot[0] == 'P' )
  1153.         { /* either active or old pitcher */
  1154.  
  1155.             if ( player->status == STATUS_MINORS )
  1156.             { /* don't bother with minor leaguers */
  1157.                 continue;
  1158.             }
  1159.  
  1160.             /* Read from start to Weeks for active players, or end for inactive
  1161.                 ones.  Make sure we don't go too far tho */
  1162.             if ( !pdb_pitchstats( &player->pname, player->start-1,
  1163.                 (player->status == STATUS_ACTIVE ? Weeks :
  1164.                     (player->end < Weeks? player->end : Weeks)),
  1165.                     &pchblk ))
  1166.             { /* can't find it, so zero and use it! */
  1167.                 pchblk.ps_outs = pchblk.ps_er = pchblk.ps_bb = pchblk.ps_hits =
  1168.                     pchblk.ps_won  = pchblk.ps_lost = pchblk.ps_saved = 0;
  1169.             }
  1170.  
  1171.             if ( player->start < Weeks &&
  1172.                    player->end < Weeks &&
  1173.                     player->status != STATUS_ACTIVE &&
  1174.                     player->status != STATUS_RESERVE )
  1175.             { /* just count the old stuff */
  1176.                 team->oldp.ps_outs += pchblk.ps_outs;
  1177.                 team->oldp.ps_er += pchblk.ps_er;
  1178.                 team->oldp.ps_bb += pchblk.ps_bb;
  1179.                 team->oldp.ps_hits += pchblk.ps_hits;
  1180.                 team->oldp.ps_won  += pchblk.ps_won ;
  1181.                 team->oldp.ps_lost += pchblk.ps_lost;
  1182.                 team->oldp.ps_saved += pchblk.ps_saved;
  1183.             }
  1184.  
  1185.             if ( player->start <= Weeks )
  1186.             { /* tally up playing players */
  1187.                 team->pitchers.ps_outs += pchblk.ps_outs;
  1188.                 team->pitchers.ps_er += pchblk.ps_er;
  1189.                 team->pitchers.ps_bb += pchblk.ps_bb;
  1190.                 team->pitchers.ps_hits += pchblk.ps_hits;
  1191.                 team->pitchers.ps_won  += pchblk.ps_won ;
  1192.                 team->pitchers.ps_lost += pchblk.ps_lost;
  1193.                 team->pitchers.ps_saved += pchblk.ps_saved;
  1194.             }
  1195.         }
  1196.     }
  1197. }
  1198.  
  1199.  
  1200.  
  1201. /* Fetch next player in slot order. */
  1202. static RDB_PLAYER *next_player ARGLIST( ( teamP, playerP ) )
  1203.     NFARG( RDB_TEAM *teamP )
  1204.      FARG( RDB_PLAYER *playerP )
  1205. {
  1206.     int    slotN;                        /* Slot number looking for */
  1207.     RDB_PLAYER *lowP;                    /* Ptr to lowest seen */
  1208.  
  1209.     /* If any current player, see if there's another with equal slot.
  1210.         Can happen with special expansion slots or with invalid slots. */
  1211.     if ( playerP != NULL )
  1212.     {
  1213.         slotN = playerP->slot;
  1214.         for( playerP = playerP->next; playerP != NULL; playerP = playerP->next )
  1215.         {
  1216.             if ( playerP->slot == slotN )
  1217.             {    /* Matching slot; we'll take this one. */
  1218.                 return ( playerP );
  1219.             }
  1220.         }
  1221.     }
  1222.     else
  1223.     {    /* No last player; look for lowest slot. */
  1224.         slotN = -2;                            /* Slot must be greater than this. */
  1225.     }
  1226.  
  1227.     for ( lowP = NULL, playerP = teamP->players; playerP != NULL;
  1228.                     playerP = playerP->next )
  1229.     {
  1230.  
  1231.         if ( playerP->slot <= slotN )
  1232.         {    /* Can't take this one. */
  1233.             continue;
  1234.         }
  1235.  
  1236.         if ( lowP == NULL )
  1237.         {    /* First valid one seen; remember it. */
  1238.             lowP = playerP;
  1239.         }
  1240.         else if ( playerP->slot < lowP->slot )
  1241.         {    /* This one's better. */
  1242.             lowP = playerP;
  1243.         }
  1244.     }
  1245.  
  1246.     /* Return whatever we found. */
  1247.     return ( lowP );
  1248. }
  1249.